package cn.wolfcode.wolf2w.advice;

import cn.wolfcode.wolf2w.exception.LogicException;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class CommonExceptionHandler {
    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object logicException(LogicException e){
        e.printStackTrace();
        JsonResult logicerror = JsonResult.error(JsonResult.CODE_ERROR, e.getMessage(), null);
        return logicerror;
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object exception(Exception e){
        e.printStackTrace();
        JsonResult logicerror = JsonResult.defaultError();
        return logicerror;
    }
}
